#include "../header/matrix.h"

matrixXY::matrixXY(int width,int height)
{
    this->_width = width;
    this->_height = height;
    this->_matrix = (float*)malloc(sizeof(float)*width*height);
    memset(_matrix,0,sizeof(float)*width*height);
}

matrixXY::~matrixXY()
{
    free(_matrix);
}

float* matrixXY::operator[](int i) {
    return _matrix+i*_height;
}

matrixXY& matrixXY::multi(matrixXY& a, matrixXY& b){
    if(a._width!=b._height)
        throw("ERROR IN MATRIX MULTIPLY");
    
    matrixXY c(b._width,a._height);

    for(int c1=0;c1<c._width;c1++){
        for(int c2=0;c2<c._height;c2++) {
            for(int c3=0;c3<a._width;c3++) {
                c[c1][c2]+=a[c3][c2]*b[c1][c3];
            }
        }
    }
}